
using System.Diagnostics;
using WYJ.SDK.Core;
using WYJ.SDK.Web;

try
{
    var builder = App.Launch(args);
    builder.Services.AddControllers();
    var app = builder.Build();


    app.Use((context, next) =>
    {
        if (context.Request.Path == "/")
        {
            context.Request.Path += "index.html";
        }
        return next(context);
    });
    
    app.UseStaticFiles();

    app.UseRouting();

    app.UseCors(App.AppSettings.CorsPolicy);

    app.Use((context, next) =>
    {
        string? t = context.Request.Cookies["token"]?.ToString();
        if (Token.TryParse(t, out var token))
        {
            context.Items["token"] = token;
        }
            return next(context);
    });
    app.MapControllers();

    Process.Start("explorer", App.AppSettings.Urls);
    app.Run(App.AppSettings.Urls);

}
catch (Exception ex)
{
    WYJConsole.PrintException(ex);
    Console.ReadKey();
}


